package org.example.mybooksystem.Modle;

import lombok.Data;
import org.example.mybooksystem.enums.ResultCode;

/**
 * Created with IntelliJ IDEA.
 * Description:做渐进主义的改良派,不做完没注意的速成派
 * User: XALEXC
 * Date: 2025-03-06
 * Time: 15:29
 */
@Data
public class Result {

    /**
     * 业务状态码
     */
    private ResultCode code; // 0 -成功    -1 失败  -2 未登录

    /**
     * 错误信息
     */
    private String errMsg;

    /**
     * 数据
     */
    private Object data;

    public static Result success(Object data) {
        Result result=new Result();
        result.setCode(ResultCode.SUCCESS);
        result.setData(data);
        result.setErrMsg("");
        return result;
    }

    public static Result fail(String errMsg, Object data) {
        Result result=new Result();
        result.setCode(ResultCode.FAIL);
        result.setData(data);
        result.setErrMsg(errMsg);
        return result;
    }

    public static Result fail(String errMsg) {
        Result result=new Result();
        result.setCode(ResultCode.FAIL);
        result.setErrMsg(errMsg);
        return result;
    }

    public static Result unlogin(){
        Result result=new Result();
        result.setCode(ResultCode.UNLOGIN);
        System.out.println(result.code);
        result.setErrMsg("用户未登录");
        result.setData("null");
        return result;
    }

}
